<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;

class Goods extends Model
{
    // 出售商品
    protected $table = "goods";
    public $timestamps = false;
    protected $guarded = ['id'];

    public function kind()
    {
        return $this->belongsTo('App\Kind');
    }

    public function craftsman()
    {
        return $this->belongsTo('App\Craftsman');
    }

    public function order()
    {
        return $this->hasMany('App\Goods_Order', 'item_id');
    }

    protected static function booted()
    {
        static::addGlobalScope('orderCount', function (Builder $builder) {
            $builder->withCount('order');
        });
    }
}
